/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 10:32:21 AM
 * To change this template use File | Settings | File Templates.
 */
import dk.brics.automaton.Automaton;
import java.io.IOException;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import org.jdom.*;

// Referenced classes of package dk.brics.dsd:
//            Context, InternalSchemaErrorException, SchemaErrorException, Escape,
//            Declaration, Rule, Boolexp, Schema,
//            Regexp, ValidationErrorHandler

public class Validator
{

    public Validator(ValidationErrorHandler validationerrorhandler)
    {
        error_handler = validationerrorhandler;
        try
        {
            enable_debug = System.getProperty("DEBUG") != null;
        }
        catch(SecurityException securityexception) { }
    }

    public void setRepeatMin(boolean flag)
    {
        repeat_hack = flag;
    }

    public static Document makeDocument(String s, URL url)
        throws JDOMException, MalformedURLException, IOException
    {
        return Template.makeDocument(s, url);
    }

    public static Document makeDocument(URL url)
        throws JDOMException, MalformedURLException, IOException
    {
        return Template.makeDocument(url);
    }

    public static String findDSDref(Document document)
    {
        List list = document.getContent();
        for(Iterator iterator = list.iterator(); iterator.hasNext();)
        {
            Object obj = iterator.next();
            if(obj instanceof ProcessingInstruction)
            {
                ProcessingInstruction processinginstruction = (ProcessingInstruction)obj;
                if(processinginstruction.getTarget().equals("dsd"))
                    return processinginstruction.getPseudoAttributeValue("href");
            }
        }

        return null;
    }

    public Document process(Document document, Schema schema, boolean flag)
        throws SchemaErrorException
    {
        resetPostponedErrors();
        Boolexp.resetMemo();
        Context context = new Context(document.getRootElement(), this);
        normalize(context, schema, new HashSet());
        schema.checkRoot(context);
        validateDeclReqs(context, schema, new HashSet());
        if(!flag)
        {
            HashMap hashmap = new HashMap();
            checkUniqueness(context, context, schema, hashmap);
            checkPointers(context, context, schema, hashmap);
            insertPostponedErrors();
        }
        Boolexp.resetMemo();
//        break MISSING_BLOCK_LABEL_130;
        Object obj;
//        obj;
//        throw new SchemaErrorException();
//        obj;
        insertPostponedErrors();
        Boolexp.resetMemo();
//        break MISSING_BLOCK_LABEL_130;
        Exception exception;
//        exception;
        Boolexp.resetMemo();
//        throw exception;
        return document;
    }

    public Document process(Document document, Schema schema)
        throws SchemaErrorException
    {
        return process(document, schema, false);
    }

    public void process(Graph graph, Schema schema)
        throws SchemaErrorException
    {
label0:
        {
            try
            {
                graph.setReverseEdges();
                Boolexp.resetMemo();
                Set set = getRoots(graph);
                HashSet hashset = new HashSet();
                resetNormalizationMaps();
                for(Iterator iterator = set.iterator(); iterator.hasNext(); normalize((Context)iterator.next(), schema, hashset));
                schema.checkRoots(set);
                hashset = new HashSet();
                for(Iterator iterator1 = set.iterator(); iterator1.hasNext(); validateDeclReqs((Context)iterator1.next(), schema, hashset));
            }
            catch(InternalSchemaErrorException internalschemaerrorexception)
            {
                throw new SchemaErrorException();
            }
            catch(Escape escape)
            {
                Boolexp.resetMemo();
                resetNormalizationMaps();
                break label0;
            }
            finally
            {
                Boolexp.resetMemo();
                resetNormalizationMaps();
//                throw exception;
            }
            Boolexp.resetMemo();
            resetNormalizationMaps();
            break label0;
        }
    }

    private Set getRoots(Graph graph)
    {
        HashSet hashset = new HashSet();
        Iterator iterator = graph.getRoots().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Node node = (Node)iterator.next();
            if(getRoots(node, graph, ((Set) (hashset)), ((Set) (new HashSet()))))
                invalid(new Context(graph, node, null, this), "non-whitespace character data around root element", null);
            if(maxRootElements(node, graph, new Stack(), new Stack(), new HashMap()) > 1)
                invalid(new Context(graph, node, null, this), "potentially multiple root elements", null);
            if(minRootElements(node, graph, new Stack(), new HashMap()) < 1)
                invalid(new Context(graph, node, null, this), "potentially no root element", null);
        } while(true);
        return hashset;
    }

    private boolean getRoots(Node node, Graph graph, Set set, Set set1)
    {
        if(set1.contains(node))
            return false;
        set1.add(node);
        boolean flag = false;
        Iterator iterator = node.getTemplate().getXML().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Object obj = iterator.next();
            if((obj instanceof Text) || (obj instanceof CDATA))
            {
                String s;
                if(obj instanceof Text)
                    s = ((Text)obj).getText();
                else
                    s = ((CDATA)obj).getText();
                if(!isWhitespace(s))
                    flag = true;
            } else
            if(obj instanceof Element)
            {
                Element element = (Element)obj;
                if(Template.isGap(element) && graph != null)
                {
                    Iterator iterator1 = node.lookupTemplateEdges(Template.getGap(element)).iterator();
                    while(iterator1.hasNext())
                    {
                        TemplateEdge templateedge = (TemplateEdge)iterator1.next();
                        flag |= getRoots(templateedge.getDestination(), graph, set, set1);
                    }
                } else
                {
                    set.add(new Context(graph, node, element, this));
                }
            }
        } while(true);
        return flag;
    }

    private int maxRootElements(Node node, Graph graph, Stack stack, Stack stack1, HashMap hashmap)
    {
        Integer integer = (Integer)hashmap.get(node);
        if(integer != null)
            return integer.intValue();
        if(stack1.contains(node))
            return 0;
        if(stack.contains(node))
            stack1.push(node);
        else
            stack.push(node);
        int i = 0;
        Iterator iterator = node.getTemplate().getXML().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Object obj = iterator.next();
            if(obj instanceof Element)
            {
                Element element = (Element)obj;
                if(Template.isGap(element) && graph != null)
                {
                    int j = 0;
                    Iterator iterator1 = node.lookupTemplateEdges(Template.getGap(element)).iterator();
                    do
                    {
                        if(!iterator1.hasNext())
                            break;
                        TemplateEdge templateedge = (TemplateEdge)iterator1.next();
                        int k = maxRootElements(templateedge.getDestination(), graph, stack, stack1, hashmap);
                        if(k > j)
                            j = k;
                    } while(true);
                    i += j;
                } else
                {
                    i++;
                }
            }
        } while(true);
        if(stack1.contains(node))
            stack1.pop();
        else
            stack.pop();
        hashmap.put(node, new Integer(i));
        return i;
    }

    private int minRootElements(Node node, Graph graph, Stack stack, HashMap hashmap)
    {
        Integer integer = (Integer)hashmap.get(node);
        if(integer != null)
            return integer.intValue();
        if(stack.contains(node))
            return 2;
        stack.push(node);
        int i = 0;
        Iterator iterator = node.getTemplate().getXML().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Object obj = iterator.next();
            if(obj instanceof Element)
            {
                Element element = (Element)obj;
                if(Template.isGap(element) && graph != null)
                {
                    if(!node.getOpenGaps().contains(Template.getGap(element)))
                    {
                        int j = 2;
                        Iterator iterator1 = node.lookupTemplateEdges(Template.getGap(element)).iterator();
                        do
                        {
                            if(!iterator1.hasNext())
                                break;
                            TemplateEdge templateedge = (TemplateEdge)iterator1.next();
                            int k = minRootElements(templateedge.getDestination(), graph, stack, hashmap);
                            if(k < j)
                                j = k;
                        } while(true);
                        i += j;
                    }
                } else
                {
                    i++;
                }
            }
        } while(true);
        stack.pop();
        hashmap.put(node, new Integer(i));
        return i;
    }

    List getChildren(Context context)
    {
        ArrayList arraylist = new ArrayList();
        chardata = false;
        getChildren(context, context.e.getContent(), ((List) (arraylist)), ((Set) (new HashSet())));
        return arraylist;
    }

    private void getChildren(Context context, List list, List list1, Set set)
    {
        Iterator iterator = list.iterator();
label0:
        do
        {
            if(!iterator.hasNext())
                break;
            Object obj = iterator.next();
            if((obj instanceof Text) || (obj instanceof CDATA))
            {
                String s;
                if(obj instanceof Text)
                    s = ((Text)obj).getText();
                else
                    s = ((CDATA)obj).getText();
                if(!isWhitespace(s))
                    chardata = true;
                continue;
            }
            if(!(obj instanceof Element))
                continue;
            Element element = (Element)obj;
            if(Template.isGap(element) && context.sg != null)
            {
                Iterator iterator1 = context.n.lookupTemplateEdges(Template.getGap(element)).iterator();
                do
                {
                    if(!iterator1.hasNext())
                        continue label0;
                    TemplateEdge templateedge = (TemplateEdge)iterator1.next();
                    Node node = templateedge.getDestination();
                    if(!set.contains(node))
                    {
                        set.add(node);
                        getChildren(new Context(context.sg, node, null, context.this_n, context.this_e, context.v), node.getTemplate().getXML(), list1, set);
                    }
                } while(true);
            }
            list1.add(new Context(context.sg, context.n, element, context.this_n, context.this_e, context.v));
        } while(true);
    }

    static Set getParents(Context context)
    {
        HashSet hashset = new HashSet();
        if(context.sg == null)
        {
            org.jdom.Parent parent = context.e.getParent();
            if(parent != null && (parent instanceof Element))
                hashset.add(new Context((Element)parent, context.this_e, context.v));
        } else
        {
            getParents(context, hashset, new HashSet());
        }
        return hashset;
    }

    private static void getParents(Context context, Set set, Set set1)
    {
        Element element = (Element)context.e.getParent();
        if(element != null)
        {
            set.add(new Context(context.sg, context.n, element, context.this_n, context.this_e, context.v));
        } else
        {
            Iterator iterator = context.n.getReverseEdges().iterator();
            do
            {
                if(!iterator.hasNext())
                    break;
                Location location = (Location)iterator.next();
                if(!set1.contains(location))
                {
                    set1.add(location);
                    getParents(new Context(context.sg, location.getNode(), location.getElement(), context.this_n, context.this_e, context.v), set, set1);
                }
            } while(true);
        }
    }

    static String whitespaceString(boolean flag, String s)
    {
        StringBuffer stringbuffer = new StringBuffer();
        boolean flag1 = flag;
        for(int i = 0; i < s.length(); i++)
        {
            char c = s.charAt(i);
            boolean flag2 = isWhitespace(c);
            if(!flag1 || !flag2)
            {
                stringbuffer.append(flag2 ? ' ' : c);
                flag1 = flag2;
            }
        }

        if(flag)
        {
            int j = stringbuffer.length() - 1;
            if(j >= 0 && isWhitespace(stringbuffer.charAt(j)))
                stringbuffer.deleteCharAt(j);
        }
        return stringbuffer.toString();
    }

    private void normalizeAttributeWhitespace(Attribute attribute, String s)
    {
        boolean flag = s.equals("trim");
        if(s.equals("compress") || flag)
            attribute.setValue(whitespaceString(flag, attribute.getValue()));
    }

    private void normalizeAttributeCase(Attribute attribute, String s)
    {
        if(s.equals("upper"))
            attribute.setValue(attribute.getValue().toUpperCase());
        else
        if(s.equals("lower"))
            attribute.setValue(attribute.getValue().toLowerCase());
    }

    private void resetNormalizationMaps()
    {
        contents_whitespace = new HashMap();
        contents_case = new HashMap();
        attribute_whitespace = new HashMap();
        attribute_case = new HashMap();
        attribute_gap_defaults = new HashMap();
    }

    private void normalizeContentsWhitespace(Context context, String s)
    {
        boolean flag;
        if(s.equals("trim"))
            flag = true;
        else
        if(s.equals("compress"))
            flag = false;
        else
            return;
        if(context.sg == null)
        {
            Iterator iterator = context.e.getContent().iterator();
            do
            {
                if(!iterator.hasNext())
                    break;
                Object obj = iterator.next();
                if(obj instanceof Text)
                {
                    Text text = (Text)obj;
                    text.setText(whitespaceString(flag, text.getText()));
                } else
                if(obj instanceof CDATA)
                {
                    CDATA cdata = (CDATA)obj;
                    cdata.setText(whitespaceString(flag, cdata.getText()));
                }
            } while(true);
        } else
        {
            contents_whitespace.put(context.e, s);
        }
    }

    private void normalizeContentsCase(Context context, String s)
    {
        boolean flag;
        if(s.equals("upper"))
            flag = true;
        else
        if(s.equals("lower"))
            flag = false;
        else
            return;
        if(context.sg == null)
        {
            Iterator iterator = context.e.getContent().iterator();
            do
            {
                if(!iterator.hasNext())
                    break;
                Object obj = iterator.next();
                if(obj instanceof Text)
                {
                    Text text = (Text)obj;
                    if(flag)
                        text.setText(text.getText().toUpperCase());
                    else
                        text.setText(text.getText().toLowerCase());
                } else
                if(obj instanceof CDATA)
                {
                    CDATA cdata = (CDATA)obj;
                    if(flag)
                        cdata.setText(cdata.getText().toUpperCase());
                    else
                        cdata.setText(cdata.getText().toLowerCase());
                }
            } while(true);
        } else
        {
            contents_case.put(context.e, s);
        }
    }

    String getAttributeGapDefault(Element element, String s)
    {
        Map map = (Map)attribute_gap_defaults.get(element);
        if(map == null)
            return null;
        else
            return (String)map.get(s);
    }

    private void normalize(Context context, Schema schema, Set set)
    {
        if(set.contains(context))
            return;
        set.add(context);
        String s = context.e.getNamespaceURI();
        if(s.equals("http://www.brics.dk/DSD/2.0/error") || s.equals("http://www.brics.dk/DSD/2.0/meta"))
            return;
        debug("normalizing element " + context.e.getQualifiedName());
        List list = findDeclarations(schema.findApplicableRules(context));
        HashMap hashmap = new HashMap();
        HashMap hashmap1 = new HashMap();
        if(context.sg == null)
        {
            attribute_whitespace = new HashMap();
            attribute_case = new HashMap();
        }
        for(ListIterator listiterator = list.listIterator(list.size()); listiterator.hasPrevious(); ((Declaration)listiterator.previous()).collectAttributeNormalization(context, hashmap, attribute_whitespace, attribute_case, hashmap1));
        for(Iterator iterator = hashmap.values().iterator(); iterator.hasNext(); context.e.setAttribute((Attribute)iterator.next()));
        hashmap = null;
        Attribute attribute;
        for(Iterator iterator1 = hashmap1.values().iterator(); iterator1.hasNext(); ((Map)attribute_gap_defaults.get(context.e)).put(attribute.getName(), attribute.getValue()))
        {
            attribute = (Attribute)iterator1.next();
            if(!attribute_gap_defaults.containsKey(context.e))
                attribute_gap_defaults.put(context.e, new HashMap());
        }

        hashmap1 = null;
        if(context.sg == null)
        {
            java.util.Map.Entry entry;
            for(Iterator iterator2 = attribute_whitespace.entrySet().iterator(); iterator2.hasNext(); normalizeAttributeWhitespace((Attribute)entry.getKey(), (String)entry.getValue()))
                entry = (java.util.Map.Entry)iterator2.next();

            java.util.Map.Entry entry1;
            for(Iterator iterator3 = attribute_case.entrySet().iterator(); iterator3.hasNext(); normalizeAttributeCase((Attribute)entry1.getKey(), (String)entry1.getValue()))
                entry1 = (java.util.Map.Entry)iterator3.next();

            attribute_whitespace = null;
            attribute_case = null;
        }
        list = findDeclarations(schema.findApplicableRules(context));
        boolean flag = true;
        boolean flag1 = true;
        boolean flag2 = true;
        List list1 = getChildren(context);
        if(list1.size() > 0 || chardata)
            flag = false;
        ListIterator listiterator1 = list.listIterator(list.size());
        do
        {
            if(!listiterator1.hasPrevious() || !flag && !flag1 && !flag2)
                break;
            Declaration declaration = (Declaration)listiterator1.previous();
            if(flag)
            {
                List list2 = declaration.getDefaultContents();
                if(list2 != null)
                {
                    context.e.setContent(list2);
                    flag = false;
                }
            }
            if(flag1)
            {
                String s1 = declaration.getContentsWhitespace();
                if(s1 != null)
                {
                    normalizeContentsWhitespace(context, s1);
                    flag1 = false;
                }
            }
            if(flag2)
            {
                String s2 = declaration.getContentsCase();
                if(s2 != null)
                {
                    normalizeContentsCase(context, s2);
                    flag2 = false;
                }
            }
        } while(true);
        list = null;
        for(Iterator iterator4 = getChildren(context).iterator(); iterator4.hasNext(); normalize((Context)iterator4.next(), schema, set));
    }

    private void validateDeclReqs(Context context, Schema schema, Set set)
    {
        if(set.contains(context))
            return;
        set.add(context);
        String s = context.e.getNamespaceURI();
        if(s.equals("http://www.brics.dk/DSD/2.0/error") || s.equals("http://www.brics.dk/DSD/2.0/meta"))
            return;
        debug("validating element " + context.e.getQualifiedName());
        SortedSet sortedset = schema.findApplicableRules(context);
        HashSet hashset = new HashSet();
        for(Iterator iterator = sortedset.iterator(); iterator.hasNext(); ((Rule)iterator.next()).checkRequirements(context, hashset));
        checkAttributeDeclarations(context, sortedset);
        checkContentsDeclarations(context, hashset);
        for(Iterator iterator1 = getChildren(context).iterator(); iterator1.hasNext(); validateDeclReqs((Context)iterator1.next(), schema, set));
    }

    private List findDeclarations(SortedSet sortedset)
    {
        ArrayList arraylist = new ArrayList();
        for(Iterator iterator = sortedset.iterator(); iterator.hasNext(); ((Rule)iterator.next()).findDeclarations(arraylist));
        return arraylist;
    }

    private void checkAttributeDeclarations(Context context, SortedSet sortedset)
    {
        List list = findDeclarations(sortedset);
        Iterator iterator = context.e.getAttributes().iterator();
label0:
        do
        {
            if(!iterator.hasNext())
                break;
            Attribute attribute = (Attribute)iterator.next();
            if(attribute.getNamespaceURI().equals("http://www.brics.dk/DSD/2.0/meta"))
                continue;
            debug("checking attribute " + attribute.getQualifiedName());
            if(Template.isGap(attribute) && context.sg != null)
            {
                String s = Template.getGap(attribute);
                StringEdge stringedge = context.n.lookupStringEdge(s);
                if(stringedge != null)
                {
                    Automaton automaton = Automaton.makeEmpty();
                    for(Iterator iterator2 = list.iterator(); iterator2.hasNext();)
                    {
                        Declaration declaration1 = (Declaration)iterator2.next();
                        automaton = declaration1.addAttributeLabels(attribute.getName(), context, automaton);
                    }

                    Automaton automaton1 = stringedge.getLabels().intersection(Regexp.getAllchars().repeat());
                    if(context.sg.getOpenAttributeGaps().contains(s))
                    {
                        String s1 = getAttributeGapDefault(context.e, attribute.getName());
                        if(s1 != null)
                            automaton1 = automaton1.union(Automaton.makeString(s1));
                    }
                    String s2 = (String)attribute_whitespace.get(attribute);
                    String s3 = (String)attribute_case.get(attribute);
                    automaton = Regexp.normalizeWhitespace(automaton, s2);
                    automaton1 = Regexp.normalizeCase(automaton1, s3);
                    if(!automaton1.subsetOf(automaton))
                        if(automaton1.intersection(automaton).isEmpty())
                            invalid(context, "attribute gap '" + attribute.getName() + "' in element " + getElementName(context.e) + " not declared");
                        else
                            invalid(context, "attribute gap '" + attribute.getName() + "' in element " + getElementName(context.e) + " not always declared");
                }
                continue;
            }
            boolean flag = false;
            for(Iterator iterator1 = list.iterator(); iterator1.hasNext();)
            {
                Declaration declaration = (Declaration)iterator1.next();
                if(declaration.attributeNameMatch(attribute, context))
                    flag = true;
                if(declaration.attributeMatch(attribute, context))
                    continue label0;
            }

            if(flag)
                invalid(context, "value '" + attribute.getValue() + "' of attribute " + getAttributeName(attribute) + " in element " + getElementName(context.e) + " not declared");
            else
                invalid(context, "attribute " + getAttributeName(attribute) + " in element " + getElementName(context.e) + " not declared");
        } while(true);
    }

    static boolean isWhitespace(char c)
    {
        return c == ' ' || c == '\t' || c == '\r' || c == '\n';
    }

    static boolean isWhitespace(String s)
    {
        for(int i = 0; i < s.length(); i++)
            if(!isWhitespace(s.charAt(i)))
                return false;

        return true;
    }

    private void checkContentsDeclarations(Context context, Set set)
    {
        debug("checking contents");
        HashSet hashset = new HashSet();
        Iterator iterator = getChildren(context).iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Element element = ((Context)iterator.next()).e;
            String s = element.getNamespaceURI();
            if(!s.equals("http://www.brics.dk/DSD/2.0/error") && !s.equals("http://www.brics.dk/DSD/2.0/meta") && !set.contains(element))
                hashset.add(element);
        } while(true);
        for(Iterator iterator1 = hashset.iterator(); iterator1.hasNext(); invalid(context, "sub-element " + getElementName((Element)iterator1.next()) + " of element " + getElementName(context.e) + " not declared"));
        if(chardata && !set.contains(null))
            invalid(context, "character data in element " + getElementName(context.e) + " not declared");
    }

    static String getElementName(Element element)
    {
        String s = element.getNamespacePrefix();
        if(s.equals(""))
            return "'" + element.getName() + "' (" + element.getNamespaceURI() + ")";
        else
            return "'" + element.getQualifiedName() + "' (" + s + ":" + element.getNamespaceURI() + ")";
    }

    static String getAttributeName(Attribute attribute)
    {
        String s = attribute.getNamespacePrefix();
        if(s.equals(""))
            return "'" + attribute.getName() + "'";
        else
            return "'" + attribute.getQualifiedName() + "' (" + s + ":" + attribute.getNamespaceURI() + ")";
    }

    void invalid(Context context, String s)
    {
        invalid(context, s, null);
    }

    void invalid(Context context, String s, Element element)
    {
        if(context.sg == null)
        {
            Element element1 = (new Element("error", "http://www.brics.dk/DSD/2.0/error")).addContent(s);
            if(element != null)
                element1.addContent(element);
            context.e.getContent().add(0, element1);
        }
        if(!error_handler.error(context.n, context.e, s, element))
            throw new Escape();
        else
            return;
    }

    void invalid2(Context context, String s, Element element)
    {
        Element element1 = (new Element("error", "http://www.brics.dk/DSD/2.0/error")).addContent(s);
        if(element != null)
            element1.addContent(element);
        postponed_errors.put(element1, context.e);
        if(!error_handler.error(context.n, context.e, s, element))
            throw new Escape();
        else
            return;
    }

    void resetPostponedErrors()
    {
        postponed_errors = new HashMap();
    }

    void insertPostponedErrors()
    {
        if(postponed_errors != null)
        {
            java.util.Map.Entry entry;
            for(Iterator iterator = postponed_errors.entrySet().iterator(); iterator.hasNext(); ((Element)entry.getValue()).getContent().add(0, entry.getKey()))
                entry = (java.util.Map.Entry)iterator.next();

            postponed_errors = null;
        }
    }

    static void debug(String s)
    {
        if(enable_debug)
            System.err.println(" - " + s);
    }

    private void checkUniqueness(Context context, Context context1, Schema schema, Map map)
    {
        String s = context.e.getNamespaceURI();
        if(s.equals("http://www.brics.dk/DSD/2.0/error") || s.equals("http://www.brics.dk/DSD/2.0/meta"))
            return;
        debug("checking uniqueness for element '" + context.e.getQualifiedName() + "'");
        Iterator iterator = schema.findApplicableRules(context).iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Rule rule = (Rule)iterator.next();
            if(!rule.skipProcessing(context))
                rule.checkUniqueness(new Context(context1.e, context.e, context.v), new HashSet(), map, context1.e);
        } while(true);
        for(Iterator iterator1 = context.e.getChildren().iterator(); iterator1.hasNext(); checkUniqueness(new Context((Element)iterator1.next(), context.v), context1, schema, map));
    }

    private void checkPointers(Context context, Context context1, Schema schema, Map map)
    {
        String s = context.e.getNamespaceURI();
        if(s.equals("http://www.brics.dk/DSD/2.0/error") || s.equals("http://www.brics.dk/DSD/2.0/meta"))
            return;
        debug("checking pointers for element '" + context.e.getQualifiedName() + "'");
        for(Iterator iterator = schema.findApplicableRules(context).iterator(); iterator.hasNext(); ((Rule)iterator.next()).checkPointers(context, map, context1.e));
        for(Iterator iterator1 = context.e.getChildren().iterator(); iterator1.hasNext(); checkPointers(new Context((Element)iterator1.next(), context.v), context1, schema, map));
    }

    static final String dsdns = "http://www.brics.dk/DSD/2.0";
    static final String metans = "http://www.brics.dk/DSD/2.0/meta";
    static final String errorns = "http://www.brics.dk/DSD/2.0/error";
    private ValidationErrorHandler error_handler;
    private static boolean enable_debug;
    static boolean repeat_hack;
    Map contents_whitespace;
    Map contents_case;
    Map attribute_whitespace;
    Map attribute_case;
    Map attribute_gap_defaults;
    boolean chardata;
    private Map postponed_errors;
}

